package com.rules.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rules.admin.entity.DubboModel;
import com.rules.admin.service.DubboService;
import com.rules.admin.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping({"/dubbo"})
@Controller
public class DubboController {
   @Autowired
   private DubboService dubboService;

   @RequestMapping(
      value = {"dubbo_page"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public IPage<DubboModel> queryPage(DubboModel dubboModel, IPage<DubboModel> page) {
      return this.dubboService.queryPage(dubboModel, page);
   }

   @RequestMapping(
      method = {RequestMethod.POST}
   )
   @ResponseBody
   public Map<String, Object> addRemote(@RequestBody DubboModel dubboModel) {
      this.dubboService.save(dubboModel);
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> getDubbo(@PathVariable("id") String id) {
      DubboModel dubboModel = (DubboModel)this.dubboService.getById(Long.parseLong(id));
      return ResultUtils.getSuccessResultData(dubboModel);
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.DELETE}
   )
   @ResponseBody
   public Map<String, Object> deleteDubbo(@PathVariable("id") String id) {
      this.dubboService.removeById(Long.parseLong(id));
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      method = {RequestMethod.PUT}
   )
   @ResponseBody
   public Map<String, Object> updateDubbo(@RequestBody DubboModel dubboModel) {
      this.dubboService.save(dubboModel);
      return ResultUtils.getSuccessResultData();
   }
}
